/**************************************************************************/
/*                                                                        */
/* Copyright (c) SinoEmbed Technology Co.,Ltd.           */
/*  */
/*                                                                        */
/*                                                                        */
/*    created:    2012-8-15                                           */ 
/*    filename:   FileBrowserWnd.h                                          */ 
/*    author:     Derek Huang                                                  */  
/*    purpose:                                                            */ 
/*                                                                        */
/* ************************************************************************/

#ifndef __I_FILEBROWSER_WND_H__
#define __I_FILEBROWSER_WND_H__
#include <mzfc_inc.h>
//#include    "xmlParser.h"
//#include    <../include/xmlParser.h>
//#include    "IXmlParser.h"
//#include "iCalendarUi.h"
#include "iUiButton.h"
#include "BrowserList.h"
#include "ManagerFileItem.h"
#include "PlayList.h"

typedef struct tagListXML
{
	UINT nCtlID;
	RECT rtRange;
	UINT nItemHeight;
	UINT nItemID;
	COLORREF TextColor;
	RECT rtText;
	UINT nLeftIconID;
	RECT rtLeftIcon;
	UINT nRightIconID;
	RECT rtRightIcon;
	UINT nDownIconID;
	RECT rtDownIcon;
//	UINT nSignalIconID;
//	RECT rtSignalIcon;

}ListXML,*PListXML;


typedef enum _tagFileListBtnDisplay
{
	FILE_LIST_CLOSE = 0,
	FILE_LIST_ADDONE,
	FILE_LIST_ADDALL,
	FILE_LIST_DELONE,
	FILE_LIST_DELALL,
	MAX_FILE_LIST_BTN,
} FILE_LIST_BTN;
typedef enum _tagFileType
{
	FILE_TYPE_VIDEO = 0,
	FILE_TYPE_MUSIC,
	MAX_FILE_TYPE,
} FILE_TYPE;

class CFileBrowserWnd : public CMzWndEx
{
	MZ_DECLARE_DYNAMIC(CFileBrowserWnd);
public:
	CFileBrowserWnd();
	CFileBrowserWnd(TCHAR *pRootPath, DWORD dwVirtualDiscItem = 0);
	virtual ~CFileBrowserWnd();
		virtual void PaintWin(HDC hdc, RECT* prcUpdate /* = NULL */);
	virtual BOOL OnInitDialog();
	virtual  void OnMzCommand(WPARAM wParam, LPARAM lParam);
	virtual LRESULT MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam);
	virtual void OnPaint(HDC hdc, LPPAINTSTRUCT ps);

	virtual void OnLButtonDown(UINT fwKeys, int xPos, int yPos);
	virtual void OnLButtonUp(UINT fwKeys, int xPos, int yPos);
	virtual void OnMouseMove(UINT fwKeys, int xPos, int yPos);

private:
//	ListXML m_ResultListXML;
	void LoadResultListRes();
//	CiTaskItemList m_ResultList;
public:
/*
	LONG XmlQueryBtnItemValue(CXmlParser*, CMzString &strXml, iUiButton &VideoMainUIItem);
//	LONG XmlQueryListItemValue(CXmlParser* xmlParser,CMzString &strXml, CBrowserList &ListUIItem);
	LONG XmlQueryListItemValue(CXmlParser* xmlParser,CMzString &strXml, CPlayList &ListUIItem);
	LONG XmlQueryPlayListItemValue(CXmlParser* xmlParser,CMzString &strXml, CPlayList &ListUIItem);
//	BOOL InitBrowserDir(CMzString &strPath, CManagerFileItem &managerFileItem);
*/	UINT InitBrowserDir(CMzString &strPath, CVPlayerManagerFileItem &managerFileItem, int nPos = -1);
	UINT DeleteBrowserDir(UINT nPos);
	UINT OpenDir(UINT nItem);
	UINT CloseDir(UINT nItem);
	BOOL GetNextFile(TCHAR **szFilePath,TCHAR **szFileName);
	BOOL GetPrevFile(TCHAR **szFilePath,TCHAR **szFileName);
	void OnExit();
	void OnAddOne();
	void OnAddAll();
	void OnDelOne();
	void OnDelAll();
	HDC				m_hBakDC;
	HDC				m_hBkgndDC;
	HBITMAP			m_hBitmapBakDC;
	HBITMAP			m_hBitmapBkgndDC;
	HBITMAP			m_hBitmapBkgnd;
	RECT			m_rtCalendarWordSpace;
	RECT			m_rtOffset;
	int				m_nXOffsetList;
	int				m_nYOffsetList;
//	RECT			m_rtCalendarBkgnd;
	RECT			m_rtFileBrowserBkgnd;
	RECT			m_rtCalendarMove;
	ImagingHelper *m_pimgBkgnd;
	UINT	m_nBkgndID;
	iUiButton	m_BtnFileList[MAX_FILE_LIST_BTN];
//	CMzString		m_strXmlPIDCancel;
	CMzString		m_strXmlPIDBtn[MAX_FILE_LIST_BTN];
	UiWin	m_uiWin;

//	CBrowserList   m_BrowserList;
	CPlayList		m_BrowserList;
	CPlayList		m_PlayList;
	CMzString		m_strXmlPIDList[MAX_FILE_TYPE];
	CMzString		m_strXmlPlayList[MAX_FILE_TYPE];
	ListXML m_ResultListXML;
	CVPlayerManagerFileItem m_ManagerFileItem;
	CVPlayerManagerFileItem m_ManagerPlayFileItem[DISC_MAX];
	DWORD m_dwVirtualDiscItem;
	CMzString		m_strRootPath;

	UINT			m_nIndex[DISC_MAX];
	HANDLE      m_hDeviceMsgThread;
	static DWORD DeviceMsgProc(LPVOID lpParameter);
	HANDLE m_hStopDeviceMsg;
	void DestroyBrowserList();
	void CreatePlayList(int nIndex);
	void SetCurrentDiscIndex(DWORD dwVirtualDiscItem){m_dwVirtualDiscItem = dwVirtualDiscItem;};
	void DestroyPlayManagerList(int nIndex);
	void DestroyPlayList();
	void CreateBrowserList();
	void CreateBrowserList(TCHAR *pList);
private:
	CRITICAL_SECTION m_Lock;
public:
	std::vector<wstring> mfilters;
	BOOL InitBackgrandImages();
	inline void Lock(BOOL bLock){bLock ? EnterCriticalSection(&m_Lock):LeaveCriticalSection(&m_Lock);};
	void LoadPlayListFromExtStorage();
	void SavePlayListtoExtStorage();

};


#endif